@list = map { int rand(100) } 1..shift;
print "@list\n";

@res = (100) x 5;                         # (-1) for max

for ($i=0; $i<@list; $i++) 
{
    for ($y=0; $y<@res; $y++) 
    {
        if ($list[$i]<$res[$y])           # > for max
        {
            for ($z=$#res; $z>$y; $z--)
            {
                $res[$z] = $res[$z-1];
            }
            $res[$y] = $list[$i];
            last;
        }
    }
}

print "@res\n";
print join " ", grep !$dup{$_}++, @res;